// import { message } from 'antd';
import { postData, exportData } from './index'

export default {
    getCouponData:(data, callback)=>{        
        return postData('/market/coupon/couponList',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    getCouponInfo:(data, callback)=>{        
        return postData('/market/coupon/couponInfo',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    getBusinessLevelSelect:(data, callback)=>{        
        return postData(process.env.Text[3]+'/center/product/businesslevel/validList',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    //自营机构
    getProductList:(data, callback)=>{
        return postData(process.env.Text[3]+'/center/product/base/list',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    // 慧简学机构-自营产品
    getSelfProductList:(data, callback)=>{
        return postData(process.env.Text[3]+'/center/hjxSelfSale/product/base/list',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    // 慧简学机构-平台产品
    getPlatformProductList:(data, callback)=>{
        return postData(process.env.Text[3]+'/center/hjxPlatform/product/base/list',data).then((res) => {            
            if(res){
                callback(res);
            }
        })
    },
    createCoupon:(data, callback)=>{        
        return postData('/market/coupon/addCoupon',data).then((res) => {       
            res?callback(true):callback(false);
        })
    },    
    deleteCoupon:(data, callback)=>{        
        return postData('/market/coupon/deleteCoupon',data).then((res) => {         
            if(res){                
                callback(res);
            }
        })
    },      
    getEditCouponStatus:(data, callback)=>{ //编辑优惠券       
        return postData('/market/coupon/editCoupon',data).then((res) => {         
            res?callback(true):callback(false);
        })
    }, 
    getOrgList:(data, callback)=>{        
        return postData(process.env.Text[3]+'/center/sys/org/notDleteOrgs',data).then((res) => {         
            if(res){                            
                callback(res);
            }
        })
    },     
    getDataOverviewData:(data, callback)=>{ //数据概览 
        return postData('/market/coupon/getView',data).then((res) => {         
            if(res){                
                callback(res);
            }
        })
    },              
    getHeroList:(data, callback)=>{ //英雄榜 
        return postData('/market/coupon/heroView',data).then((res) => {         
            if(res){                
                callback(res);
            }
        })
    },     
    exportCouponAnalysis:(data, callback)=>{ //导出券分析数据 
        return exportData('/market/coupon/exportExcel',data).then((res) => {                   
            if(res){                
                callback(res);
            }
        })
    },        
    getCouponProductList:(data, callback)=>{ //获取优惠券对应的产品信息 
        return postData('/market/coupon/couponProInfo',data).then((res) => {               
            if(res instanceof Array){                
                if(res.length > 0){
                    let _newArray = res.map((item)=>(
                        {
                            ...item,
                            id:item.productId,
                            name:item.productName
                        }))
                    callback(_newArray)
                }else{
                    callback(res);
                }
            }
        })
    }, 
}